// import { HardhatUserConfig } from 'hardhat/config'

require("@nomicfoundation/hardhat-toolbox");
// hardhat.config.js
require("@openzeppelin/hardhat-upgrades");
require("dotenv").config();
require("@nomicfoundation/hardhat-verify");

require("hardhat-contract-sizer");
//合约验证
// require('@nomiclabs/hardhat-etherscan')

if (!process.env.TEST === "true") {
  require("hardhat-gas-reporter");
}

// // hardhat.config.ts
// import '@openzeppelin/hardhat-upgrades';

/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
  defaultNetwork: "hardhat",
  networks: {
    // Test Networks
    // hardhat: {
    //   chainId: 1337,
    //   accounts: {
    //     mnemonic: process.env.WALLET_MNEMONIC,
    //     count: 10,
    //   },
    //   throwOnTransactionFailures: true,
    //   throwOnCallFailures: false,
    //   loggingEnabled: true,
    //   allowUnlimitedContractSize: false,
    //   gas: 0xfffffffffff,
    //   gasPrice: 10000000000,
    //   initialBaseFeePerGas: 0,
    // },
    ganache: {
      url: "http://127.0.0.1:7545",
      chainId: 5777,
      accounts: {
        mnemonic: process.env.GANACHE_WALLET_MNEMONIC || "",
        count: 10,
      },
    },
    goerli: {
      url: process.env.ETH_NODE_URL,
      chainId: 5,
      gas: 2100000,
      gasPrice: 4000000000,
      accounts: {
        mnemonic: process.env.WALLET_MNEMONIC || "",
        count: 10,
      },
    },
    sepolia: {
      url: process.env.SEPOLIA_NODE_URL,
      chainId: 11155111,
      // gas: 2100000,
      // gas: 21000000,
      // gasPrice: 50000000000,
      // accounts: {
      //   mnemonic: process.env.WALLET_MNEMONIC || '',
      //   count: 10,
      // },
      accounts: [process.env.SEPOLIA_LEONARD_PRIVATE],
    },
    rinkeby: {
      url: process.env.ETH_NODE_URL,
      chainId: 4,
      gas: 2100000,
      gasPrice: 4000000000,
      accounts: {
        mnemonic: process.env.WALLET_MNEMONIC || "",
        count: 10,
      },
    },
    ropsten: {
      url: process.env.ETH_NODE_URL,
      chainId: 3,
      gas: 2100000,
      gasPrice: 4000000000,
      accounts: {
        mnemonic: process.env.WALLET_MNEMONIC || "",
        count: 10,
      },
    },
    harmonytest: {
      url: process.env.ETH_NODE_URL,
      chainId: 1666700000,
      gas: 2100000,
      gasPrice: 10000000000,
      accounts: {
        mnemonic: process.env.WALLET_MNEMONIC || "",
        count: 10,
      },
    },
    polygontest: {
      url: process.env.ETH_NODE_URL,
      chainId: 80001,
      gas: 2100000,
      gasPrice: 10000000000,
      accounts: {
        mnemonic: process.env.WALLET_MNEMONIC || "",
        count: 10,
      },
    },
    coverage: {
      url: "http://127.0.0.1:8555",
      chainId: 1,
      gas: 0xfffffffffff,
      gasPrice: 10000000000,
      initialBaseFeePerGas: 0,
    },

    // Main Networks
    mainnet: {
      url: process.env.ETH_NODE_URL,
      chainId: 1,
      // accounts: {
      //   mnemonic: process.env.WALLET_MNEMONIC || "",
      //   count: 10,
      // },
      accounts: [process.env.SEPOLIA_LEONARD_PRIVATE],
    },
    harmony: {
      url: process.env.ETH_NODE_URL,
      chainId: 1666600000,
      accounts: {
        mnemonic: process.env.WALLET_MNEMONIC || "",
        count: 10,
      },
    },
    polygon: {
      url: process.env.ETH_NODE_URL,
      chainId: 137,
      accounts: {
        mnemonic: process.env.WALLET_MNEMONIC || "",
        count: 10,
      },
    },
    ganache: {
      url: "http://localhost:7545",
      accounts: {
        mnemonic: process.env.GANACHE_WALLET_MNEMONIC || "",
        count: 10,
      },
    },
    bscTest: {
      url: process.env.BSC_TEST_NODE_URL,
      // chainId: 137,
      accounts: [
        process.env.BSC_TEST_LEONARD_PRIVATE,
        process.env.BSC_TEST_BOLEI_PRIVATE,
      ],
    },
    // cfxTest: {
    //   url: process.env.CFX_TEST_NODE_URL,
    //   chainId: 1,
    //   accounts: [
    //     process.env.CFX_TEST_LEONARD_PRIVATE,
    //     process.env.CFX_TEST_BOLEI_PRIVATE,
    //   ],
    // },
  },
  solidity: {
    version: "0.8.20",
    settings: {
      optimizer: {
        enabled: true,
      },
    },
  },

  // 我们可以指定输出文件、是否开启颜色、指定币种、指定代币名称，以及指定代币的 CoinMarketCap API 密钥来根据项目进一步控制输出。
  gasReporter: {
    enabled: true,
    // outputFile: 'gas-reporter.txt',
    // noColors: true,
    // currency: 'USD',
    // coinmarketcap: COINMARKETCAP_API_KEY,
    // token: 'MATIC',
  },

  // Project Settings
  contractSizer: {
    alphaSort: true,
    disambiguatePaths: false,
    runOnCompile: !(process.env.SOLC_OPTIMIZER === "false"),
    strict: true,
  },

  paths: {
    tests: "./test",
    sources: "./contracts",
    cache: "./build/cache",
    artifacts: "./build/artifacts",
  },
  mocha: {
    timeout: 6000000, //测试超时时间限制
  },
  etherscan: {
    // Your API key for Etherscan
    // Obtain one at https://etherscan.io/
    apiKey: {
      mainnet: process.env.ETHERSCAN_API_KEY,
      goerli: process.env.ETHERSCAN_API_KEY,
      sepolia: process.env.ETHERSCAN_API_KEY,
      bscTest: process.env.BSCSCAN_API_KEY,
    },
  },
  // sourcify: {
  //   // Disabled by default
  //   // Doesn't need an API key
  //   enabled: false,
  // },
  // 要使用 Sourcify 验证合同，您需要添加到您的 Hardhat 配置中
  sourcify: {
    enabled: false,
    // Optional: specify a different Sourcify server
    apiUrl: "https://sourcify.dev/server",
    // Optional: specify a different Sourcify repository
    browserUrl: "https://repo.sourcify.dev",
  },
};
